package com.cloudcreativity.blyg.sqlite;

import com.cloudcreativity.blyg.utils.PriceUtils;
import com.cloudcreativity.blyg.utils.StrUtils;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.ToOne;
import org.greenrobot.greendao.DaoException;

@Entity
public class Goods {

    //这是内部业务的id，跟远程商品库的id无关系，除了第一次同步商品数据外
    @Id(autoincrement = true)
    private Long lid;

    //远程商品库的商品id,用来下单时进行数据一致性处理
    private Long id;

    @NotNull
    private String name;

    private long categoryOneId;

    private long categoryTwoId;

    //商品条码
    private String barCode;

    //单位id
    private int unitId;

    //单位
    private String unit;

    //品牌id
    private int brandId;

    //品牌名
    private String brandName;

    // 规格
    private String specName;

    //零售价
    private int price;

    //库存
    private double stock;

    // 是否下架  0 上架 1下架
    private int isShelf = 0;

    @ToOne(joinProperty = "categoryOneId")
    private CategoryOne categoryOne;

    @ToOne(joinProperty = "categoryTwoId")
    private CategoryTwo categoryTwo;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 258717323)
    private transient GoodsDao myDao;

    @Generated(hash = 2107193936)
    public Goods(Long lid, Long id, @NotNull String name, long categoryOneId,
            long categoryTwoId, String barCode, int unitId, String unit,
            int brandId, String brandName, String specName, int price, double stock,
            int isShelf) {
        this.lid = lid;
        this.id = id;
        this.name = name;
        this.categoryOneId = categoryOneId;
        this.categoryTwoId = categoryTwoId;
        this.barCode = barCode;
        this.unitId = unitId;
        this.unit = unit;
        this.brandId = brandId;
        this.brandName = brandName;
        this.specName = specName;
        this.price = price;
        this.stock = stock;
        this.isShelf = isShelf;
    }

    @Generated(hash = 1770709345)
    public Goods() {
    }

    public Long getLid() {
        return this.lid;
    }

    public void setLid(Long lid) {
        this.lid = lid;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getCategoryOneId() {
        return this.categoryOneId;
    }

    public void setCategoryOneId(long categoryOneId) {
        this.categoryOneId = categoryOneId;
    }

    public long getCategoryTwoId() {
        return this.categoryTwoId;
    }

    public void setCategoryTwoId(long categoryTwoId) {
        this.categoryTwoId = categoryTwoId;
    }

    public String getBarCode() {
        return this.barCode;
    }

    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

    public int getUnitId() {
        return this.unitId;
    }

    public void setUnitId(int unitId) {
        this.unitId = unitId;
    }

    public String getUnit() {
        return this.unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public int getBrandId() {
        return this.brandId;
    }

    public void setBrandId(int brandId) {
        this.brandId = brandId;
    }

    public String getBrandName() {
        return this.brandName;
    }

    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }

    public String getSpecName() {
        return this.specName;
    }

    public void setSpecName(String specName) {
        this.specName = specName;
    }

    public int getPrice() {
        return this.price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public double getStock() {
        return this.stock;
    }

    public void setStock(double stock) {
        this.stock = stock;
    }

    public int getIsShelf() {
        return this.isShelf;
    }

    public void setIsShelf(int isShelf) {
        this.isShelf = isShelf;
    }

    @Generated(hash = 611682569)
    private transient Long categoryOne__resolvedKey;

    /** To-one relationship, resolved on first access. */
    @Generated(hash = 1143978361)
    public CategoryOne getCategoryOne() {
        long __key = this.categoryOneId;
        if (categoryOne__resolvedKey == null
                || !categoryOne__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            CategoryOneDao targetDao = daoSession.getCategoryOneDao();
            CategoryOne categoryOneNew = targetDao.load(__key);
            synchronized (this) {
                categoryOne = categoryOneNew;
                categoryOne__resolvedKey = __key;
            }
        }
        return categoryOne;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 550214596)
    public void setCategoryOne(@NotNull CategoryOne categoryOne) {
        if (categoryOne == null) {
            throw new DaoException(
                    "To-one property 'categoryOneId' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.categoryOne = categoryOne;
            categoryOneId = categoryOne.getId();
            categoryOne__resolvedKey = categoryOneId;
        }
    }

    @Generated(hash = 1463454230)
    private transient Long categoryTwo__resolvedKey;

    /** To-one relationship, resolved on first access. */
    @Generated(hash = 759152052)
    public CategoryTwo getCategoryTwo() {
        long __key = this.categoryTwoId;
        if (categoryTwo__resolvedKey == null
                || !categoryTwo__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            CategoryTwoDao targetDao = daoSession.getCategoryTwoDao();
            CategoryTwo categoryTwoNew = targetDao.load(__key);
            synchronized (this) {
                categoryTwo = categoryTwoNew;
                categoryTwo__resolvedKey = __key;
            }
        }
        return categoryTwo;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 2045050298)
    public void setCategoryTwo(@NotNull CategoryTwo categoryTwo) {
        if (categoryTwo == null) {
            throw new DaoException(
                    "To-one property 'categoryTwoId' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.categoryTwo = categoryTwo;
            categoryTwoId = categoryTwo.getId();
            categoryTwo__resolvedKey = categoryTwoId;
        }
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 2112467424)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getGoodsDao() : null;
    }

    public String formatPrice(){
        return "¥"+StrUtils.get2BitDecimal(this.price/100f);
    }
    
}
